import axios from 'axios';

// 一些请求的基本配置
const service = axios.create({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
    }
  })

export default function httpRequest(url, data={},method="get") {
    return new Promise((resolve, reject) => {
        const options = {
          url,
          method
        }
        if (method.toLowerCase() === 'get') {
          options.params = data
        } else {
          options.data = data
        }
        service(options).then(res => {
            resolve(res.data)
        })
        .catch(error => {
          reject()
          console.error(error)
        })
    })
}